﻿package Cain.MkMc 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.DisplayObject;
	/**
	 * 訊息面板
	 * @author Cain
	 */
	public class TalkBd extends AllMk {
		private var tall:String;
		private var cobk:CoBk;
		private var _root:Sprite;
		/**
		 * 對話面板
		 * @param	_mc 場景元件
		 * @param	_str 訊息
		 * @param	_alpha 背景透明度
		 * @param	_color 背景顏色
		 * @param	_s 背景淡入秒數
		 */
		public function TalkBd(_mc:DisplayObject ,_str:String,_alpha:Number = .5,_color:uint = 0,_s:Number=.5)
		{
			_root = Sprite(_mc.root);
			super(_mc, _alpha, _color, _s);
			tall = _str;
			talkBd_setup();
		}
		private function talkBd_setup():void
		{
			addEventListener(Event.ADDED_TO_STAGE, addthis);
		}
		
		private function addthis(e:Event):void 
		{
			stage.addEventListener(Event.RESIZE, onRESIZE);
			cobk = new CoBk(tall);
			addChild(cobk);
			cobk.x = _root.stage.stageWidth >> 2;
			cobk.y = _root.stage.stageHeight >> 2;
			removeEventListener(Event.ADDED_TO_STAGE, addthis);
			addEventListener(Event.REMOVED_FROM_STAGE, renovethis);
			talkBd_init();
		}
		
		private function onRESIZE(e:Event):void 
		{
			
			cobk.x = _root.stage.stageWidth >> 2;
			cobk.y = _root.stage.stageHeight >> 2;
		}
		
		private function talkBd_init():void
		{
			cobk.addEventListener(MouseEvent.CLICK,onCLICK);
		}
		
		private function onCLICK(e:MouseEvent):void 
		{
			cobk.removeEventListener(MouseEvent.CLICK, onCLICK);
			cobk.unload();
			unload();
		}
		
		private function renovethis(e:Event):void 
		{
			stage.removeEventListener(Event.RESIZE, onRESIZE);
			removeEventListener(Event.REMOVED_FROM_STAGE, renovethis);
		}
	}
	
}